package com.hbnu.system.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hbnu.system.core.base.CommonPage;
import com.hbnu.system.core.base.Rest;
import com.hbnu.system.model.dto.CheckBackDTO;
import com.hbnu.system.model.dto.SearchPageDTO;
import com.hbnu.system.model.dto.UserDTO;
import com.hbnu.system.model.entity.Lecture;
import com.hbnu.system.model.entity.Lecturefile;
import com.hbnu.system.service.ILectureService;
import com.hbnu.system.service.ILecturefileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2023-05-16
 */
@RestController
@RequestMapping("/lecture")
@Api(tags = "学术讲座模块")
public class LectureController {
    @Autowired
    ILectureService iLectureService;

    @Autowired
    ILecturefileService iLecturefileService;
    @ApiOperation("学术讲座录入")
    @PostMapping("/addLecture")
    public Rest<Boolean> AddLecture(@RequestBody Lecture lecture){
        boolean add = iLectureService.addlecture(lecture);
        return add ? Rest.success() : Rest.failed();
    }

    @ApiOperation("学术讲座删除")
    @GetMapping("/DeleteLecture")
    public Rest<Boolean> DeleteLecture(String ID){
        boolean delete = iLectureService.deletelecture(ID);
        return delete ? Rest.success() : Rest.failed();
    }

    @ApiOperation("学术讲座提交")
    @GetMapping("/ReCommitLecture")
    public Rest<Boolean> ReCommitLecture(String ID){
        boolean add = iLectureService.ReCommitlecture(ID);
        return add ? Rest.success() : Rest.failed();
    }
    @ApiOperation("学术讲座名称查重")
    @GetMapping("/ChecklectureName")
    public Rest<Boolean> ChecklectureName(String name){
        boolean check = iLectureService.checklectureName(name);
        return check ? Rest.success() : Rest.failed();
    }

    @ApiOperation("学术讲座修改")
    @PostMapping("/UpdateLecture")
    public Rest<Boolean> UpdateLecture(@RequestBody Lecture lecture){
        boolean delete = iLectureService.updatelecture(lecture);
        return delete ? Rest.success() : Rest.failed();
    }

    @ApiOperation("根据主键学术讲座查询")
    @GetMapping("/GetlectureById")
    public Rest<Lecture> GetLectureById(String ID){
        Lecture mt = iLectureService.getlecturebyid(ID);
        return Rest.success(mt);
    }
    @ApiOperation("学术讲座分页查询")
    @PostMapping ("/pagecondition")
    public Rest<CommonPage<Lecture>> pageProjectCondition(@RequestBody SearchPageDTO searchTaskDTO){
        IPage<Lecture> page = iLectureService.pageCondition(searchTaskDTO);
        CommonPage<Lecture> activityVOCommonPage = CommonPage.restPage(page);
        return Rest.success(activityVOCommonPage);
    }
    @ApiOperation("学术讲座校级通过")
    @GetMapping("/SchoolCheckPass")
    public Rest<String> SchoolPasslecture(@RequestHeader("X-Token") String token,String PID){
        Boolean b = iLectureService.schoolCheckPass(token,PID);
        return b ? Rest.success() : Rest.failed();
    }
    @ApiOperation("学术讲座校级打回")
    @PostMapping("/SchoolCheckBack")
    public Rest<String> SchoolBacklecture(@RequestHeader("X-Token") String token,@RequestBody CheckBackDTO checkBackDTO){
        Boolean b = iLectureService.schoolCheckBack(token,checkBackDTO);
        return b ? Rest.success() : Rest.failed();
    }
    @ApiOperation("用户获取与自己相关的学术讲座分页")
    @PostMapping("/UserGetRelateLecture")
    public Rest<CommonPage<Lecture>> UserGetRelatelecture(@RequestBody UserDTO userDTO){
        IPage<Lecture> mtIPage = iLectureService.userGetRelateLecture(userDTO);
        CommonPage<Lecture> mtCommonPage = CommonPage.restPage(mtIPage);
        return Rest.success(mtCommonPage);
    }

//    @ApiOperation("院级管理员查看需要自己审核的论文-分页")
//    @PostMapping("/CollegeUserGetPaper")
//    public Rest<CommonPage<Paper>> CollegeUserGetPaper(@RequestBody UserDTO userDTO){
//        IPage<Paper> paperIPage = iPaperService.collegeUserGetPaper(userDTO);
//        CommonPage<Paper> paperCommonPage = CommonPage.restPage(paperIPage);
//        return Rest.success(paperCommonPage);
//    }

    @ApiOperation("校级管理员查看需要自己审核的学术讲座分页")
    @PostMapping("/SchoolUserGetLecture")
    public Rest<CommonPage<Lecture>> SchoolUserGetlecture(@RequestBody UserDTO userDTO){
        IPage<Lecture> mtIPage = iLectureService.schoolUserGetLecture(userDTO);
        CommonPage<Lecture> mtCommonPage = CommonPage.restPage(mtIPage);
        return Rest.success(mtCommonPage);
    }
    @ApiOperation("学术讲座-文件信息上传")
    @PostMapping("/addLecturefile")
    public Rest<Boolean> addLecturefile(@RequestBody Lecturefile lecturefile){
        boolean add = iLecturefileService.addLecturefile(lecturefile);
        return add ? Rest.success() : Rest.failed();
    }
    @ApiOperation("学术讲座-文件信息删除")
    @GetMapping("/DeleteLecturefile")
    public Rest<Boolean> DeleteLecturefile(String ID)throws IOException {
        boolean delete = iLecturefileService.deletLecturefile(ID);
        return delete ? Rest.success() : Rest.failed();
    }
    @ApiOperation("学术讲座-文件信息分页查询")
    @GetMapping ("/pageLecturefileCondition")
    public Rest<List<Lecturefile>> pageLecturefileConditionfile(String id){
        List<Lecturefile> page = iLecturefileService.pageLecturefile(id);
        return Rest.success(page);
    }
    @ApiOperation("学术讲座-文件信息修改")
    @PostMapping("/updateLecturefile")
    public Rest<Boolean> updateLecturefile(@RequestBody Lecturefile lecturefile){
        boolean update = iLecturefileService.updateLecturefile(lecturefile);
        return update ? Rest.success() : Rest.failed();
    }
}

